Fontes: http://especiais.g1.globo.com/monitor-da-violencia/2018/mortes-violentas-no-brasil/?_ga=2.62510572.1711685417.1581424139-28686389.1558827135#/dados-mensais-2019?mes_2019=consolidado&estado=TO&estado_compare=AC&crime=Todos%20os%20crimes%20violentos

https://static.poder360.com.br/2020/10/Anuario-2020-FINAL.pdf

Gráfico 1 - Evolução homicídios (1980-2018)

x<-1980:2018
y<-c(11.69,12.56,12.57,13.77,15.32,15.00,15.26,16.89,16.78,20.30,22.22,20.94,19.21,20.20,21.23,23.84,24.78,25.39,25.94,26.20,27.35,27.86,28.53,29.14,26.94,26.13,26.61,26.20,26.72,27.18,27.80,27.45,29.41,28.55,29.82,28.89,30.33,31.59,27.8)
z<-c(rep(NA,24),y[25:39])
y<-c(y[1:25],rep(NA,14))

resultado2<-data.frame(x=x,y=y,z=z)

fig <- plot_ly(resultado2, x = x, y = y, type = 'scatter', mode = 'lines',line = list(color = 'rgb(255, 255, 255)',dash = 'dash', width = 2),name = 'Taxa de Homicídios (1980-2003)')
fig <- fig %>% add_trace(y = ~z,line = list(color = 'rgb(205, 12, 24)', width = 3,dash = F),name = 'Taxa de Homicídios (2004-2018)')

fig <- fig %>% layout(legend = list(x = 0.1, y = 0.9),plot_bgcolor='rgb(25,25,25)', paper_bgcolor='rgb(0, 0, 0)',
        yaxis = list(title="Homicídios por 100 mil habs.",zeroline = T, tickfont = list(size = 26,color = 'rgba(255, 255, 255, .9)'), titlefont = list(size = 26,color = 'rgba(255, 255, 255, .9)')),
         xaxis = list(title="",zeroline = T,tickfont = list(size = 26,color = 'rgba(255, 255, 255, .9)'),titlefont = list(size = 26,color = 'rgba(255, 255, 255, .9)')))

fig
MannKendall(y)
## tau = 0.9, 2-sided pvalue =< 2.22e-16

Gráfico 2 - Correlação Armas Registradas (SINARM) x Crimes violentos por 100 mil habs.

## 
## Call:
## lm(formula = taxa ~ armas, data = resultado2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -11.812  -4.939  -1.096   6.529  10.129 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.886e+01  1.673e+00  17.249 2.15e-15 ***
## armas       -1.050e-04  2.638e-05  -3.978 0.000524 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.84 on 25 degrees of freedom
## Multiple R-squared:  0.3877, Adjusted R-squared:  0.3632 
## F-statistic: 15.83 on 1 and 25 DF,  p-value: 0.0005237

Gráfico 3 - Armas Registradas (SINARM) x Total de crimes violentos

df<-read.csv("taxa_homicidios_crimes_violentos.txt", sep="\t",h=T)

armas<-df$armas
total_crimes<-df$TAXA_CRIMES_VIOLENTOS
taxa_crimes_violentos<-df$homicidios

x<-armas
y<-total_crimes
z<-taxa_crimes_violentos

resultado2<-data.frame(armas=x,taxa=y,total=z)

fit <- lm(taxa~total,data=resultado2)

fig3<-resultado2 %>% 
  plot_ly(x = ~armas) %>% add_lines(x = ~armas, y = fitted(fit),line=list(color='red')) %>% 
  add_markers(y = ~total,color = 'rgba(152, 0, 0, .8)',marker=list(size=15,color = 'rgba(255, 255, 255, .9)',line = list(color = 'rgb(205, 12, 24)',width = 3))) %>% 
  
  layout(showlegend = FALSE,
         #title = 'ARMAS x HOMICÍDIOS',font=list(size = 16,color = 'rgba(255, 255, 255, .9)'),
         plot_bgcolor='rgb(25,25,25)', paper_bgcolor='rgb(0, 0, 0)',
         yaxis = list(title="Total de crimes violentos",zeroline = T, tickfont = list(size = 26,color = 'rgba(255, 255, 255, .9)'), titlefont = list(size = 26,color = 'rgba(255, 255, 255, .9)')),
         xaxis = list(title="Armas registradas (SINARM)",zeroline = T,tickfont = list(size = 26,color = 'rgba(255, 255, 255, .9)'),titlefont = list(size = 26,color = 'rgba(255, 255, 255, .9)')))


fig3
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
summary(fit)
## 
## Call:
## lm(formula = taxa ~ total, data = resultado2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -17.9780  -7.3391  -0.2354   8.4424  12.1138 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 2.449e+01  2.643e+00   9.267 1.46e-09 ***
## total       1.669e-04  1.319e-03   0.126      0.9    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.738 on 25 degrees of freedom
## Multiple R-squared:  0.0006397,  Adjusted R-squared:  -0.03933 
## F-statistic: 0.016 on 1 and 25 DF,  p-value: 0.9003
######################################################################